<?php
    class Event extends CActiveRecord
    {
        public static function model($className = __CLASS__) {
            return parent::model ( $className );
        }

        public function tableName() {                  
            return 'c_event';
        }

        public function getEventHome(){
            $cacheService = new CacheService("Event","getEventHome");
            $key = $cacheService->createKey();
            $cache = Yii::app()->cache->get($key);
            $cache=false;
            if ($cache == false) 
            {
                $sql = "SELECT id,gameId,title,title_game,alias FROM c_event WHERE  status= 1 ORDER BY create_date DESC LIMIT 4";
                $command = Yii::app()->db->createCommand($sql);
                $row = $command->queryAll();                                                                 
                Yii::app()->cache->set($key, $row, ConstantsUtil::TIME_CACHE_3600);
            }
            else
            {
                $row=$cache;
            } 
            return $row;
        }
        public function getEventById($id){
            $sql = "SELECT * FROM c_event WHERE status=1 AND gameId =".$id;
            $command = Yii::app()->db->createCommand($sql);
            $row = $command->queryRow();
            return $row; 
        }
    }
?>
